package com.yiqi.lottery.feature.lottery.view;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;

import butterknife.BindView;
import butterknife.ButterKnife;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
import com.suozhang.framework.component.recyclerview.DividerItemDecoration;
import com.suozhang.framework.entity.bo.PageData;
import com.suozhang.framework.framework.BaseActivity;
import com.suozhang.framework.utils.T;
import com.suozhang.framework.widget.EmptyView;
import com.yiqi.lottery.R;
import com.yiqi.lottery.entity.bo.CircleBo;
import com.yiqi.lottery.entity.bo.FoucsBo;
import com.yiqi.lottery.feature.find.contract.CircleContract;
import com.yiqi.lottery.feature.find.dependencies.circle.CirclePresenterModule;
import com.yiqi.lottery.feature.find.dependencies.circle.DaggerCircleComponent;
import com.yiqi.lottery.feature.lottery.view.adapter.WinningAdapter;

import javax.inject.Inject;

import java.util.List;

public class FocusEventActivity extends BaseActivity implements BaseQuickAdapter.OnItemClickListener, CircleContract.View,
        OnRefreshListener {

    @BindView(R.id.toolbar)
    Toolbar mToolbar;
    @BindView(R.id.rv_foucs)
    RecyclerView mRvFoucs;
    @BindView(R.id.smartRefreshLayout)
    SmartRefreshLayout mSmartRefreshLayout;
    private WinningAdapter mAdapter;
    List<CircleBo> mCircleBos;

    @Inject
    CircleContract.Presenter mPresenter;
    private EmptyView mEmptyView;

    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_focus_event;
    }

    @Override
    protected void initInjector() {
        DaggerCircleComponent.builder().circlePresenterModule(new CirclePresenterModule(this)).build().inject(this);
    }

    @Override
    protected void initView() {
        initToolBar(mToolbar, "焦点赛事", true, true);
        initAdapter();
    }

    @Override
    protected void initData() {
//        mPresenter.doGetCircleList(0, 2, 6);
        mPresenter.getJiaodian();
    }

    private void initAdapter() {
        mSmartRefreshLayout.setOnRefreshListener(this);
        mAdapter = new WinningAdapter();
        mEmptyView = new EmptyView(mRvFoucs);
        mRvFoucs.setLayoutManager(new LinearLayoutManager(this));
        mRvFoucs.addItemDecoration(new DividerItemDecoration(DividerItemDecoration.VERTICAL).setHeight(2));
        mAdapter.bindToRecyclerView(mRvFoucs);
        mAdapter.setOnItemClickListener(this);

    }


    @Override
    public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
        Intent intent = new Intent(this, CommonWebActivity.class);
        intent.putExtra("id", mCircleBos.get(position).getPost_id() + "");
        startActivity(intent);
    }

    @Override
    public void showCircleListSuccess(PageData<CircleBo> circleBoPageData) {
        mCircleBos = circleBoPageData.getList();
        mSmartRefreshLayout.finishRefresh();
        mAdapter.setNewData(circleBoPageData.getList());
    }

    @Override
    public void showCircleListMoreSuccess(PageData<CircleBo> circleBoPageData) {

    }

    @Override
    public void showCircleMoreErrorMsg(String msg) {

    }

    @Override
    public void showDetailSuccess(FoucsBo foucsBo) {

    }

    @Override
    public void showCircleListError(String error) {
        mSmartRefreshLayout.finishRefresh();
        mAdapter.setEmptyView(mEmptyView.getErrorView(error));

        mAdapter.setNewData(null);
    }

    @Override
    public void showCircleListEmpty() {

    }

    @Override
    public void showDaiaZanSuccess(String msg) {
        showMsg(msg);
    }

    @Override
    public void showDaiaZanError(String msg) {
        showMsg(msg);
    }


    @Override
    public void onRefresh(@NonNull RefreshLayout refreshLayout) {
        initData();
    }
}
